;(function($){

	var head = "<div id='d_id' style='overflow:hidden;display:none;border:1px solid rgba(255,255,255,0.5);padding-top:30px;;position:relative;width:300px;top:150px;left:150%;z-index:9999;border-radius:5px;box-shadow:0 25px 45px rgba(0,0,0,0.1);'>"+
		"	<div id='d_title'   style='background: linear-gradient(to bottom, rgba(2,1,253,1), rgba(2,1,253,0.5));line-height:30px;font-size:12px;width:100%;height:30px;color:#ffffff;position:absolute;top:0;left:0;cursor:move;border-radius:5px 5px 0 0;'>"+
		"		<span id='d_uploading' style='padding-left:10px;'>tip</span>"+
		"		<span style='float:right;margin:5px 10px;color:#fff;line-height:20px;font-family:monospace;cursor:pointer;font-size:12px;font-weight:700;display: inline-block;width:20px;height: 20px;border-radius:50%;background: #FE437D;text-align: center;'>"+
		"       	<svg class=\"icon\" width=\"20px\" height=\"20px\" viewBox=\"0 0 1024 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\"><path fill=\"#ffffff\" d=\"M512 451.669333l211.2-211.2 60.330667 60.330667-211.2 211.2 211.2 211.2-60.330667 60.330667-211.2-211.2-211.2 211.2-60.330667-60.330667 211.2-211.2-211.2-211.2L300.8 240.469333z\" /></svg>" +
		"		</span>"+
		"	</div>"+
		"<div style=\"width: 100%;height: 100%;position: absolute;top:0;z-index:-1;\">\n" +
		"    <div style=\"filter:blur(40px);height: 40%;width: 100%;position:absolute;top: 0;left: 0;background: #1b73bd;\"></div>\n" +
		"    <div style=\"filter:blur(80px);height: 40%;width: 40%;position:absolute;bottom: 20px;left: 0;background: #f6d881;\"></div>\n" +
		"</div>"+
		"	<div style='min-height:70px;padding:20px;background-color:rgba(255,255,255,0.9);line-height:15px;position:relative;border-radius:0 0 5px 5px;'>";

	var aler = "		<div style='position:absolute;top:22%;left:30px;width:25px;height:25px;border-radius:50%;background:#F09049;line-height:25px;text-align: center;font-family:monospace;font-size:24px;color:#fff;'>!</div>"+
		"		<div style='margin-left:20%;margin-top:4%;font-size:12px;color:#333;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;' title='msg'>msg</div>";
	var process ="<div style='background:#A3B5C1;width:100%;height:10px;margin-top:20px;border-radius:5px;'>"+
		"  			<div id='d_process' style='background:#5c2;width:0%;height:100%;color:#141414;line-height:10px;border-radius:5px;' align='center'></div>"+
		"  		</div>";
	var pro = "<div style='font-size:12px;color:#333;'>"+
		"				<input type='text' id='d_value' placeholder='placeholdermsg' style='width:95%;min-height:30px;line-height:30px;padding-left:10px;outline:none;border:1px solid #999;background: rgba(255,255,255,0.5);' >"+
		"			</div>";
	var area = "<div style='font-size:12px;color:#333;'>"+
		"				<textarea id='d_value' placeholder='placeholdermsg' style='width:95%;padding-left:10px;min-height:50px;outline:none;border:1px solid #999;background: rgba(255,255,255,0.5);'></textarea>"+
		"			</div>";
	var suer = "<div style='font-size:12px;color:#333;margin-top:20px;'>"+
		"				<span id='d_ok' style='background:linear-gradient(to bottom, rgba(2,1,253,1), rgba(2,1,253,0.7));display:inline-block;width:30%;height:25px;color:#ffffff;text-align:center;line-height:25px;border-radius:2px;margin-left:15px;cursor:pointer;'>确定</span>"+
		"				<span id='d_cancel' style='background:linear-gradient(to bottom, rgba(2,1,253,1), rgba(2,1,253,0.7));display:inline-block;width:30%;height:25px;color:#ffffff;text-align:center;line-height:25px;border-radius:2px;margin-left:70px;cursor:pointer;'>取消</span>"+
		"			</div>";

	var singilesuer = "<div style='font-size:12px;color:#333;margin-top:20px;'>"+
		"				<span id='d_ok' style='background:linear-gradient(to bottom, rgba(2,1,253,1), rgba(2,1,253,0.7));display:inline-block;width:30%;height:25px;color:#ffffff;text-align:center;line-height:25px;border-radius:2px;margin-left:85px;cursor:pointer;'>确定</span>"+
		"			</div>";

	var foot = "	</div>"+
		"<div>";

	var html = head+aler+foot;
	//遮罩层
	var cover = "<div id='d_cover' class='d_cover' style='width:100%;height:9999px;background-color:rgba(0,0,0,0.2);overflow:hidden;z-index:999999;position:fixed;left:0;top:0;'></div>";
	var animate = true;
	var height = $(window).height();
	var width =  $(window).width();
	var top = "150px";
	var left = (width/2 - 150) + "px";
	/**
	 动画集合
	 */
	function rightIn($id){
		if(animate){
			$id.css({left:"150%",top:top}).show();
			$id.animate({left:left,top:top},500);
		}else{
			$id.css({left:left,top:top}).show();
		}
	}
	function rightOut($id){
		if(animate){
			$id.animate({left:"150%",top:top},500);
			$('body').css({"overflow":"auto"});
			setTimeout(function(){
				$id.parent().remove();
			},500);
		}else{
			$id.parent().remove();
		}
	}
	function leftIn($id){
		if(animate){
			$id.css({left:"-150%",top:top}).show();
			$id.animate({left:left,top:top},500);
		}else{
			$id.css({left:left,top:top}).show();
		}
	}
	function leftOut($id){
		if(animate){
			$id.animate({left:"-150%",top:top},500);
			$('body').css({"overflow":"auto"});
			setTimeout(function(){
				$id.parent().remove();
			},500);
		}else{
			$id.parent().remove();
		}
	}
	function topIn($id){
		if(animate){
			$id.css({left:left,top:"-150%"}).show();
			$id.animate({left:left,top:top},500);
		}else{
			$id.css({left:left,top:top}).show();
		}
	}
	function topOut($id){
		if(animate){
			$id.animate({left:left,top:"-150%"},500);
			$('body').css({"overflow":"auto"});
			setTimeout(function(){
				$id.parent().remove();
			},500);
		}else{
			$id.parent().remove();
		}
	}
	function bottomIn($id){
		if(animate){
			$id.css({left:left,top:"150%"}).show();
			$id.animate({left:left,top:top},500);
		}else{
			$id.css({left:left,top:top}).show();
		}
	}
	function bottomOut($id){
		if(animate){
			$id.animate({left:left,top:"150%"},500);
			$('body').css({"overflow":"auto"});
			setTimeout(function(){
				$id.parent().remove();
			},500);
		}else{
			$id.parent().remove();
		}
	}

	//为组件添加事件
	function addEvent(id,time,callback,postCallback){
		if(document.getElementById(id) != null) return;
		$("body").append($(cover.replace("d_cover",id+"cover"))).css({"overflow":"hidden"});
		$("#"+id+"cover").append($(html));
		var $id = $("#"+id+"cover").find("#"+id);
		var $title = $id.find("#d_title");
		var $image = $title.find("span");
		var arr = ["left","top","right","bottom"];
		var ani = arr[Math.round(Math.random()*3)];
		var $ok = $id.find("#d_ok");
		var $cancel = $id.find("#d_cancel");
		eval(ani+"In($id)");

		addHoverEvent($image,$ok,$cancel);
		addMoveEvent($id,$title);
		addCallBackEvent($ok,$cancel,callback,ani,$id);
		$image.bind("click", function(){
			eval(ani+"Out($id)");
		});
		if(postCallback){
			addProcessEvent($id,postCallback,ani,callback,time);
		}else{
			if(time){
				setTimeout(function(){
					eval(ani+"Out($id)");
				},time);
			}
		}
		window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
	}
	function addProcessEvent($id,postCallback,ani,callback,time){
		var timer = null;
		$('#d_processBar').find("#d_process").css({'width':'0%'}).text('0%');
		timer = setInterval(function(){
			function updateProcess(data){
				data = new Number(data);
				if(data >= 100){
					$('#d_uploading').text("完成");
					if(callback){
						$('#d_processBar').find("#d_process").css({'width':'100%'}).text('100%');
						callback(true);
						window.clearInterval(timer);
						eval(ani+"Out($id)");
					}
				}else if(data < 100){
					$('#d_processBar').find("#d_process").css({'width':data+'%'}).text(data+'%');
				}
			}
			try{
				postCallback(updateProcess)
			}catch(err) {
				console.error(err);
				if(callback){
					callback(false);
					window.clearInterval(timer);
					eval(ani+"Out($id)");
				}
			}
		},time);
	}

	function addHoverEvent($image,$ok,$cancel){
		$($image[1]).hover(function(){
			$(this).animate({
				color:"red",
				opacity: '1'
			}, 10);
		},function(){
			$(this).animate({
				opacity: '0.7'
			}, 10);
		});
		$ok.hover(function(){
			$(this).css({"background":"linear-gradient(to bottom, rgba(2,1,253,1), rgba(2,1,253,0.9))"});
		},function(){
			$(this).css({"background":"linear-gradient(to bottom, rgba(2,1,253,1), rgba(2,1,253,0.7))"});
		});
		$cancel.hover(function(){
			$(this).css({"background":"linear-gradient(to bottom, rgba(2,1,253,1), rgba(2,1,253,0.9))"});
		},function(){
			$(this).css({"background":"linear-gradient(to bottom, rgba(2,1,253,1), rgba(2,1,253,0.7))"});
		});

	}


	function addMoveEvent($id,$title){
		$(document).on("mouseup",function(){
			$id.animate({opacity:"1"},10);
			$(document).unbind("mousemove");
		});

		$title.on("mousedown",function(e){
			$id.animate({opacity:"0.5"},10);
			var offset = $id.offset();
			$(document).bind("mousemove",function(e2){
				$id.css({left:(offset.left+e2.pageX-e.pageX)+"px",top:(offset.top+e2.pageY-e.pageY)+"px"});
			});
		});
	}


	function addCallBackEvent($ok,$cancel,callback,ani,$id){
		if(typeof callback == "function"){
			if($ok){
				$ok.on("click",function(){
					var _value = $id.find("#d_value").val();
					eval(callback(true,_value));
					eval(ani+"Out($id)");
				});
			}
			if($cancel){
				$cancel.on("click",function(){
					var _value = $id.find("#d_value").val();
					eval(callback(false,_value));
					eval(ani+"Out($id)");
				});
			}
		}else{
			if($ok){
				$ok.on("click",function(){
					eval(ani+"Out($id)");
				});
			}
			if($cancel){
				$cancel.on("click",function(){
					eval(ani+"Out($id)");
				});
			}
		}
	}




	$.messager  = {
		loading:function(msg,time){
			html = head+aler+foot;
			html = html.replace("d_id","d_loading");
			html = html.replace("tip","提示");
			if(msg != null){
				html = html.replaceAll("msg",msg);
			}
			addEvent("d_loading",time|2000);
		},
		alert:function(tip,msg){
			html = head+aler+singilesuer+foot;
			html = html.replace("d_id","d_alert");
			if(tip != null){
				html = html.replace("tip",tip);
			}
			if(msg != null){
				html = html.replaceAll("msg",msg);
			}
			addEvent("d_alert");
		},
		confirm:function(tip,msg,callback){
			html = head+aler+suer+foot;
			html = html.replace("d_id","d_confirm");
			if(tip != null){
				html = html.replace("tip",tip);
			}
			if(msg != null){
				html = html.replaceAll("msg",msg);
			}
			addEvent("d_confirm",null,callback);
		},
		promp:function(tip,msg,callback){
			html = head+pro+suer+foot;
			html = html.replace("d_id","d_promp");
			if(tip != null){
				html = html.replace("tip",tip);
			}
			if(msg != null){
				html = html.replace("placeholdermsg",msg);
			}
			addEvent("d_promp",null,callback);
		},
		prompArea:function(tip,msg,callback){
			html = head+area+suer+foot;
			html = html.replace("d_id","d_prompArea");
			if(tip != null){
				html = html.replace("tip",tip);
			}
			if(msg != null){
				html = html.replace("placeholdermsg",msg);
			}
			addEvent("d_prompArea",null,callback);
		},
		processBar:function(msg,postCallback,successCallback,time){
			html = head+process+foot;
			html = html.replace("d_id","d_processBar");
			html = html.replace("tip",msg);
			html = html.replace("700;'>X","700;'>");
			addEvent("d_processBar",time|2000,successCallback,postCallback);
		}
	};
})(jQuery);